import CryptoJS from "crypto-js";
/* ========== 设置验证规则 ========== */
export const reg = {
  psw: /^.*(?=.{6,16})(?=.*\d{1,})(?=.*[a-zA-Z]{1,})(?=.*[!@#$%^&*.?\\]).*$/,
  // psw: /^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[!@#$]).{6,16}$/,
  email: /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/,
};

/* ========== 密码 加密 老版本规则 已去掉 ========== */
export const encrypt = (word, keyStr) => {
  keyStr = keyStr || "abcdefgabcdefg12";
  let key = CryptoJS.enc.Utf8.parse(keyStr); //Latin1 w8m31+Yy/Nw6thPsMpO5fg==
  let srcs = CryptoJS.enc.Utf8.parse(word);
  let encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
  return encrypted.toString();
};
/** 解密 */
export const decrypt = (word, keyStr) => {
  keyStr = keyStr || "abcdefgabcdefg12";
  let key = CryptoJS.enc.Utf8.parse(keyStr); //Latin1 w8m31+Yy/Nw6thPsMpO5fg==
  let decrypted = CryptoJS.AES.decrypt(word, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
  return CryptoJS.enc.Utf8.stringify(decrypted).toString();
};
export const getRandomArrayElements = (arr, count) => {
  let shuffled = arr.slice(0);
  let i = arr.length;
  let min = i - count;
  let temp;
  let index;
  while (i-- > min) {
    index = Math.floor((i + 1) * Math.random());
    temp = shuffled[index];
    shuffled[index] = shuffled[i];
    shuffled[i] = temp;
  }
  return shuffled.slice(min);
};
export const nationList = ["汉", "壮", "藏", "裕固", "彝", "瑶", "锡伯", "乌孜别克", "维吾尔", "佤", "土家", "土", "塔塔尔", "塔吉克", "水", "畲", "撒拉", "羌", "普米", "怒", "纳西", "仫佬", "苗", "蒙古", "门巴", "毛南", "满", "珞巴", "僳僳", "黎", "拉祜", "柯尔克孜", "景颇", "京", "基诺", "回", "赫哲", "哈萨克", "哈尼", "仡佬", "高山", "鄂温克", "俄罗斯", "鄂伦春", "独龙", "东乡", "侗", "德昂", "傣", "达斡尔", "朝鲜", "布依", "保安", "布朗", "白", "阿昌"];
